# 创建字典的语法
import os
import time

scores = {'Math': 60, 'English': 50, 'History': 80, 'French': 80}

# 创建字典的构造器语法
items1 = dict(one=1, two=2, three=3)
print('items1 = ', items1, end='\n')
# 通过 zip 函数将2个序列压成字典
print('zip功能：', zip(['one', 'two', 'three'], '123'), end='\n')
items2 = dict(zip(['one', 'two', 'three'], '123'))
print('items2 = ', items2, end='\n')
# 创建字典的推导式语法
items3 = {num: num ** 2 for num in range(1, 10)}
print('items3 = ', items3, end='\n')
# 获取对应的值
print(scores['Math'], scores['English'], end='\n')

# 遍历字典
for key, value in scores.items():
    print(f'{key} => {value}', end='\n')

# 更新元素
scores.update(Math=65, English=55)
print('scores = ', scores, end='\n')

# 添加元素
scores['Chinese'] = 90
print('scores = ', scores, end='\n')

# 获取某个元素
print('Chinese', scores.get('Chinese'), end='\n')

# 删除字典中最后一个元素
print('scores1 = ', scores.popitem(), end='\n')
print('scores = ', scores, end='\n')
print('scores2 = ', scores.popitem(), end='\n')
print('scores = ', scores, end='\n')

# 删除字典中指定元素
print('scores3 = ', scores.pop('English'), end='\n')
print('scores = ', scores, end='\n')

# 清空字典
scores.clear()
print('scores = ', scores, end='\n')


# 跑马灯
def main():
    content = '北京欢迎你，为你开天劈地......'
    while True:
        os.system('clear')
        print(content)
        time.sleep(1)
        content = content[1:] + content[0]


if __name__ == '__main__':
    main()
